/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public boolean isPalindrome(ListNode head) {
        Deque<ListNode>stack=new LinkedList<>();
        ListNode currentNode=head;
        while(currentNode!=null){
            stack.push(currentNode);
            currentNode=currentNode.next;
        }
        while(head!=null){
            if(head.val!=stack.peek().val){
                return false;
            }
            stack.pop();
            head=head.next;
        }
        return true;
    }
}
